package top.taooc.example.provider;

import top.taooc.RpcApplication;
import top.taooc.config.RegistryConfig;
import top.taooc.config.RpcConfig;
import top.taooc.example.common.service.UserService;
import top.taooc.model.ServiceMetaInfo;
import top.taooc.registry.LocalRegistry;
import top.taooc.registry.Registry;
import top.taooc.registry.RegistryFactory;
import top.taooc.server.HttpServer;
import top.taooc.server.VertxHttpServer;

/**
 * @author songtao@guishangyi.cn
 * @date 2024年06月25日 09:58:39
 * @packageName top.taooc.example.provider
 * @className EasyProivderExample
 * @Menu
 */
public class EasyProivderExample {
    public static void main(String[] args) {
        //RPC框架初始化
        RpcApplication.init();
        //注册服务
        String serviceName = UserService.class.getName();
        LocalRegistry.register(serviceName,UserServiceImpl.class);
        //注册服务到注册中心
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(serviceName);
        serviceMetaInfo.setServiceHost(rpcConfig.getServerHosts());
        serviceMetaInfo.setServicePort(rpcConfig.getServerPort());
        try {
            registry.register(serviceMetaInfo);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
        //启动web服务
        HttpServer httpServer = new VertxHttpServer();
        httpServer.doStart(RpcApplication.getRpcConfig().getServerPort());

        /*//注册服务
        LocalRegistry.register(UserService.class.getName(),UserServiceImpl.class);
        //提供服务
        VertxHttpServer httpServer = new VertxHttpServer();
        httpServer.doStart(8080);*/
    }
}
